 <template>
  <div>

    <button @click="zj()">切换组件</button>
    <keep-alive><component :is="Com"></component></keep-alive>
  </div>
</template>
 <script>
import A from "./A.vue";
import B from "./B.vue";
export default {
  components: {
    A,
    B,
  },
  data() {
    return {
      Com: "A",
    };
  },
  methods: {
    zj() {
      this.Com == "A" ? (this.Com = "B") : (this.Com = "A");
    },
  },
  computed: {},
};
</script>
 <style lang='css'>
</style>